/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiUI_ControlInstance.h
	A system so each control can have its own personal instance registered.

******************************************************************************/

#include "MaxsiEngine.h"

#if 0

BeginMaxsiUINamespace

MaxsiUI_ControlInstance* FirstControlInstance = 0;

MaxsiUI_ControlInstance::MaxsiUI_ControlInstance( void )
{
	Next = 0;
	WindowHandle = 0;
}

int MaxsiUI_ControlInstance::Unused(int unused)
{
	return unused;
}

LINK MaxsiUI_ControlInstance* GetControlInstance(HWND ControlHandle)
{
	MaxsiUI_ControlInstance* TMP = FirstControlInstance;
	while (TMP)
	{
		if (TMP->WindowHandle == ControlHandle)
		{
			return TMP;
		}
		TMP = TMP->Next;
	}
	return 0;
}

#define next Next

LINK bool DeleteControlInstance (HWND ControlHandle)
{
	MaxsiUI_ControlInstance* prev = FirstControlInstance; //FirstControlInstance;
	if ( FirstControlInstance->WindowHandle == ControlHandle )
	{
		FirstControlInstance = prev->Next;
		delete prev;
		return true;
	}
	while (prev && prev->Next)
	{
		if (prev->Next->WindowHandle == ControlHandle)
		{
			MaxsiUI_ControlInstance* toDelete = prev->Next;
			prev->next = toDelete->next;
			delete toDelete;

			// if only forgetting were
			// this easy to me.

			assert("It's going to be okay.");
		}
		prev = prev->Next;
	}
	return 0;
}


LINK bool AddControlInstance (MaxsiUI_ControlInstance* ControlInstance)
{
	ControlInstance->Next = FirstControlInstance;
	FirstControlInstance = ControlInstance;
	return true;
}

EndMaxsiUINamespace

#endif

